<template>
  <el-row type="flex" style="width:100%">
    <el-col>{{ treeNode.name }}</el-col>
    <el-col :span="4">
      <el-row type="flex">
        <el-col>{{ treeNode.manager }}</el-col>
        <el-col>
          <el-dropdown>
            <span class="el-dropdown-link">
              操作
              <i class="el-icon-arrow-down el-icon--right" />
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="addDep">添加子部门</el-dropdown-item>
              <template v-if="!isRoot">
                <el-dropdown-item @click.native="editDepFn">编辑子部门</el-dropdown-item>
                <!-- 组件上没有监听点击事件，变为原生的点击事件 -->
                <el-dropdown-item @click.native="delDep">删除子部门</el-dropdown-item>
              </template>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDepartment } from '@/api/department'
export default {
  filters: {},
  components: {

  },
  props: {
    treeNode: {
      type: Object,
      required: true },
    isRoot: {
      type: Boolean,
      default: false

    }
  },

  data() {
    return {}
  },
  computed: {},
  watch: {},
  created() {},
  methods: {
    async delDep() {
      this.$confirm('确认关闭？').then(() => {
        return delDepartment(this.treeNode.id)
      }).then(() => {
        this.$message.success('删除成功了')
        this.$emit('updateDeps')
      })
    },
    addDep() {
      this.$emit('addDep', this.treeNode)
    },
    edit() {
      this.$emit('editDep', this.treeNode)
    }
  }
}
</script>

<style scoped>

</style>
